#!/bin/sh

# 懒人专用sh脚本

# 分支检测
current_branch=$(git rev-parse --abbrev-ref HEAD) # 获取当前分支
if [ "$current_branch" != "develop" ]; then
    echo "当前分支不是develop分支"
    sleep 5
    exit
fi

# 提交
git pull

# 检查是否有冲突
if git status --porcelain | grep -q "^U"; then
    echo "有冲突，请手动解决冲突"
    exit 1
fi

echo "请填入commit内容，按回车结束"
read localBranchName
git add .
git commit -m "$localBranchName"
git push

# 传递变量以便在deploy中使用
export localBranchName

git checkout staging
git merge develop -m "合并 develop 分支"
# 检查合并过程是否遇到冲突
if [ $? -ne 0 ]; then
  echo "有冲突请手动合并"
  # 取消合并
  git merge --abort
  exit
else
  echo "合并成功，准备启动打包脚本"
  # 执行打包脚本
  ./deploy.sh
fi
